//
//  TTCategory2CellHeaderView.m
//  02-分类界面
//
//  Created by peironggao on 2017/10/28.
//  Copyright © 2017年 gaopeirong. All rights reserved.
//

#import "TTCategory2CellHeaderView.h"
#import "TTCactegoryModel.h"
#define CATEGORY1_DEFAULT_BG_COLOR [UIColor lightGrayColor]
#define CATEGORY1_SELECTED_BG_COLOR [UIColor whiteColor]
#define CELL_TITLE_FONT [UIFont systemFontOfSize:12]

#define CELL2_MARGIN_LEFT 25

@interface TTCategory2CellHeaderView ()

@property (nonatomic, weak) UILabel *titleLabel;

@end

@implementation TTCategory2CellHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = [UIColor clearColor];
        
        UILabel *titleLabel = [[UILabel alloc] init];
        [self addSubview:titleLabel];
        titleLabel.font = CELL_TITLE_FONT;
        titleLabel.textColor = [UIColor blackColor];
        _titleLabel = titleLabel;
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [_titleLabel sizeToFit];
    _titleLabel.center = CGPointMake(_titleLabel.bounds.size.width * 0.5 + CELL2_MARGIN_LEFT, self.bounds.size.height * 0.5);
}

- (void)setModel:(TTCactegoryModel *)model
{
    _model = model;
    _titleLabel.text = [NSString stringWithFormat:@"%@>", model.name];
    [_titleLabel sizeToFit];
    _titleLabel.center = CGPointMake(_titleLabel.bounds.size.width * 0.5 + CELL2_MARGIN_LEFT, self.bounds.size.height * 0.5);
}

@end
